package com.zjt.smart.ui.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.zjt.smart.R;
import com.zjt.smart.ui.customview.StateLayout;

import butterknife.Bind;

/**
 * A Activity with four-states by <code>StateLayout</code>.
 * And LoadingView-State is it's init-state.So MUST call other's state after.
 */
public abstract class StateActivity extends ToolbarActivity implements StateLayout.OnErrorClickListener{

    @Bind(R.id.stateLayout)
    protected StateLayout mStateLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mStateLayout.setErrorClickListener(this);
        showLoadingView();
    }

    protected void showLoadingView(){
        if (mStateLayout == null) return;
        mStateLayout.showLoadingView();
    }

    protected void showErrorView(){
        if (mStateLayout == null) return;
        mStateLayout.showErrorView();
    }

    protected void showContentView(){
        if (mStateLayout == null) return;
        mStateLayout.showContentView();
    }

    protected void showEmptyView(){
        if (mStateLayout == null) return;
        mStateLayout.showEmptyView();
    }

    public void setEmptyText(String emptyText){
        mStateLayout.setEmptyText(emptyText);
    }

    @Override
    public void onErrorClick() {
        showLoadingView();
    }
}
